//
//  UILabel+QuickCreate.swift
//  jiurongjk
//
//  Created by cabinzhao on 2/28/17.
//  Copyright © 2017 xuewei. All rights reserved.
//

import UIKit

extension UILabel {
    
    //根据UILabel属性快速创建对象
    public convenience init(text:String, color:UIColor, fontSize:CGFloat, isBold:Bool) {
        self.init()
        
        self.text = text
        self.textColor = color
        self.font = isBold ? UIFont(name: "Helvetica-Bold", size: fontSize) : UIFont.systemFont(ofSize: fontSize)
        self.sizeToFit()
    }
    
    public convenience init(text:String, colorHex:Int, fontSize:CGFloat, isBold:Bool) {
        self.init()
        
        self.text = text
        self.textColor = UIColor(hex: colorHex)
        self.font = isBold ? UIFont(name: "Helvetica-Bold", size: fontSize) : UIFont.systemFont(ofSize: fontSize)
        self.sizeToFit()
    }
    
    public convenience init(text:String, color:UIColor, fontSize:CGFloat, lineSpacing:CGFloat, isBold:Bool) {
        self.init()
        
        self.text = text
        self.textColor = color
        self.font = isBold ? UIFont(name: "Helvetica-Bold", size: fontSize) : UIFont.systemFont(ofSize: fontSize)
        self.numberOfLines = 0
        
        let parstyle = NSMutableParagraphStyle()
        parstyle.lineSpacing = lineSpacing
        let dic = [NSAttributedStringKey.paragraphStyle:parstyle]
        let abStr = NSAttributedString(string: text, attributes: dic)
        self.attributedText = abStr
    }
    
}
